package com.jjy.tools.dto;

import com.jjy.pojo.User;
import com.jjy.tools.encrypt.SHAencrypt;
import org.springframework.ui.Model;

import javax.servlet.http.HttpServletRequest;

public class RegistrationDto {
    //这个类的功能就是讲页面上的数据映射成一个实体类对象.
    public static User getUserFromRegister(HttpServletRequest request,Model model) throws Exception {
        User user = new User();
        String encryptPassword = SHAencrypt.encryptString(request.getParameter("password"));
        user.setAccount(request.getParameter("account"));
        user.setPassword(encryptPassword);
        user.setName(request.getParameter("name"));
        user.setGender(request.getParameter("gender"));

        if(request.getParameter("email") != ""){
            user.setEmail(request.getParameter("email"));
        } else {
            user.setEmail("12345@qq.com");
        }
        if(request.getParameter("hobbies") != ""){
            user.setHobbies(request.getParameter("hobbies"));
        } else {
            user.setHobbies("");
        }
        if(request.getParameter("homeAddress") != ""){
            user.setHomeAddress(request.getParameter("homeAddress"));
        } else {
            user.setHomeAddress("");
        }
        if(request.getParameter("job") != ""){
            user.setJob(request.getParameter("job"));
        } else {
            user.setJob("");
        }
        if(request.getParameter("mobile") != ""){
            user.setMobile(Long.valueOf(request.getParameter("mobile")));
        } else {
            user.setMobile(1888888888L);
        }
        if(request.getParameter("permission") != ""){
            user.setPermission(Integer.valueOf(request.getParameter("permission")));
        } else {
            user.setPermission(1);
        }
        if(request.getParameter("profilePhoto") != ""){
            user.setProfilePhoto(request.getParameter("profilePhoto"));
        } else {
            user.setProfilePhoto("");
        }
        return user;
    }
}
